package com.sunlands.zlcx.usercenter.config;

import org.springframework.context.annotation.Configuration;

/**
 * Created by ajGeGe on 16/8/4. 数据库相关配置 使用数据库连接池druid
 *
 * @link https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98
 * @since 1.0
 */
@Configuration
public class DatabaseConfiguration {

//    @Value("${spring.datasource.url}")
//    private String url;
//
//    @Value("${spring.datasource.username}")
//    private String username;
//
//    @Value("${spring.datasource.password}")
//    private String password;
//
//    @Value("${spring.datasource.driverClassName}")
//    private String driverName;
//
//    @Bean
//    public DataSource dataSource() {
//        HikariConfig hikariConfig = new HikariConfig();
//        hikariConfig.setJdbcUrl(url);
//        hikariConfig.setUsername(username);
//        hikariConfig.setPassword(password);
//        hikariConfig.setAutoCommit(true);
//        hikariConfig.setIdleTimeout(186000);
//        hikariConfig.setMaxLifetime(1860000);
//        hikariConfig.setMinimumIdle(16);
//        hikariConfig.setConnectionTimeout(30698);
//        hikariConfig.setMaximumPoolSize(66);
//        hikariConfig.setPoolName("gyfHikariCP");
//        hikariConfig.addDataSourceProperty("cachePrepStmts", "true");//是否自定义配置，为true时下面两个参数才生效
//        hikariConfig.addDataSourceProperty("prepStmtCacheSize", "256");//连接池大小默认25，官方推荐250-500
//        hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2046");//单条语句最大长度默认256，官方推荐2048
//        hikariConfig.addDataSourceProperty("useServerPrepStmts", "true"); //新版本MySQL支持服务器端准备，开启能够得到显著性能提升
//        hikariConfig.addDataSourceProperty("useLocalSessionState", "true");
//        hikariConfig.addDataSourceProperty("useLocalTransactionState", "true");
//        hikariConfig.addDataSourceProperty("rewriteBatchedStatements", "true");
//        hikariConfig.addDataSourceProperty("cacheResultSetMetadata", "true");
//        hikariConfig.addDataSourceProperty("cacheServerConfiguration", "true");
//        hikariConfig.addDataSourceProperty("elideSetAutoCommits", "true");
//        hikariConfig.addDataSourceProperty("maintainTimeStats", "false");
//        HikariDataSource dataSource = new HikariDataSource(hikariConfig);
//        return dataSource;
//
//    }
//
//    @Bean
//    @ConditionalOnMissingBean
//    public DataSourceTransactionManager transactionManager() {
//        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource());
//
//        return dataSourceTransactionManager;
//    }
}
